package com.woniuxy.ams.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.ams.entity.ExamineList;
import com.woniuxy.ams.entity.ExamineListFormInline;
import com.woniuxy.ams.entity.Rater;
import com.woniuxy.ams.entity.ResultEntity;
import com.woniuxy.ams.service.ExamineListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 部门考核列表controller 增删改查，同时，可查询当前一条数据的考核项及打分情况
 */
@RequestMapping("/examineList")
@RestController
public class ExamineListController {

    @Autowired(required = false)
    ExamineListService examineListServiceImpl;

    //查询部门所有考核信息
    @RequestMapping("/findExamineList")
    public ResultEntity<List<ExamineList>> findAll(@RequestParam int departmentId) {
        List<ExamineList> list = examineListServiceImpl.findAll(departmentId);
        return new ResultEntity<>(200, "查询成功", list);
    }

    //查询部门考核列表分页
    @RequestMapping("/findExamineListFormInline")
    public ResultEntity<PageInfo<ExamineList>> findAllExamineList(@RequestBody ExamineListFormInline examineListFormInline) {
        PageHelper.startPage(examineListFormInline.getCurrentPage(), examineListFormInline.getLimit());
        List<ExamineList> list = examineListServiceImpl.findAllExamineList(examineListFormInline);
        PageInfo<ExamineList> examineListPageInfo = new PageInfo<>(list);
        return new ResultEntity<>(200, "查询成功", examineListPageInfo);
    }

    //新增考核信息
    @RequestMapping("insertExamineList")
    public ResultEntity<?> insert(@RequestBody ExamineList examineList) {
        int i = examineListServiceImpl.insert(examineList);
        if (i > 0) {
            return new ResultEntity<>(200, "增加成功", "数据已录入数据库");
        } else {
            return new ResultEntity<>(500, "增加失败", "数据未录入数据库");
        }
    }

    //修改考核列表信息
    @RequestMapping("/updateExamineList")
    public ResultEntity<String> updateExamineList(@RequestBody ExamineList examineList) {
        int i = examineListServiceImpl.updateExamineList(examineList);
        if (i > 0) {
            return new ResultEntity<>(200, "修改成功", "数据已录入数据库");
        } else {
            return new ResultEntity<>(500, "修改失败", "数据未录入数据库");
        }
    }

    //删除考核列表信息
    @RequestMapping("/deleteExamineList")
    public ResultEntity<String> deleteExamineList(@RequestBody ExamineList examineList) {
        int i = examineListServiceImpl.deleteExamineList(examineList);
        if (i > 0) {
            return new ResultEntity<>(200, "删除成功", "数据已录入数据库");
        } else {
            return new ResultEntity<>(500, "删除失败", "数据未录入数据库");
        }
    }

    //通过用户信息id查一条考核信息
    @RequestMapping("/findOneExamineList")
    public ResultEntity<ExamineList> findOneExamine(@RequestParam int id) {
        ExamineList examine = examineListServiceImpl.findOneExamine(id);
        return new ResultEntity<>(200, "查询成功", examine);
    }

    //修改部门考核列表大的实际打分
    @RequestMapping("/updateScroe")
    public ResultEntity<String> updateScroe(@RequestBody Rater rater){
        int i = examineListServiceImpl.updateScroe(rater);
        if (i > 0) {
            return new ResultEntity<>(200, "修改分数成功", "数据已录入数据库");
        } else {
            return new ResultEntity<>(500, "删除分数失败", "数据未录入数据库");
        }
    }

    //修改部门考核列表考核状态（得分、状态、备注）
    @RequestMapping("/updateStatus")
    public ResultEntity<String> updateStatus(@RequestBody ExamineList examineList){
        int i = examineListServiceImpl.updateStatus(examineList);
        if (i > 0) {
            return new ResultEntity<>(200, "修改分数成功", "数据已录入数据库");
        } else {
            return new ResultEntity<>(500, "删除分数失败", "数据未录入数据库");
        }
    }

}
